{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 导入必要的包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#保存数据\n",
    "import pickle as pk\n",
    "import itertools\n",
    "\n",
    "#处理事件字符串\n",
    "import datetime\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import scipy.io as sio\n",
    "import scipy.sparse as ss\n",
    "\n",
    "#相似度/距离\n",
    "import scipy.spatial.distance as ssd\n",
    "\n",
    "from collections import defaultdict\n",
    "from sklearn.preprocessing import normalize\n",
    "\n",
    "from sklearn.cluster import MiniBatchKMeans\n",
    "from sklearn import metrics\n",
    "import time\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 用户和活动关联关系处理\n",
    "\n",
    "\n",
    "整个数据集中活动数目（events.csv）太多，所以下面的处理我们找出只在训练集和测试集中出现的活动和用户集合，并对他们重新编制索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of uniqueUsers :3391\n",
      "number of uniqueEvents :13418\n"
     ]
    }
   ],
   "source": [
    " \"\"\"\n",
    "我们只关心train和test中出现的user和event，因此重点处理这部分关联数据\n",
    "\n",
    "train.csv 有6列：\n",
    "user：用户ID\n",
    "event：活动ID\n",
    "invited：是否被邀请（0/1）\n",
    "timestamp：ISO-8601 UTC格式时间字符串，表示用户看到该活动的时间\n",
    "interested, and not_interested\n",
    "\n",
    "Test.csv 除了没有interested, and not_interested，其余列与train相同\n",
    " \"\"\"\n",
    "    \n",
    "# 统计训练集中有多少不同的用户的events\n",
    "uniqueUsers = set()\n",
    "uniqueEvents = set()\n",
    "\n",
    "#倒排表\n",
    "#统计每个用户参加的活动   / 每个活动参加的用户\n",
    "eventsForUser = defaultdict(set)\n",
    "usersForEvent = defaultdict(set)\n",
    "    \n",
    "for filename in [\"train.csv\", \"test.csv\"]:\n",
    "    f = open(filename, 'rb')\n",
    "    \n",
    "    #忽略第一行（列名字）\n",
    "    f.readline().strip().decode().split(\",\")\n",
    "    \n",
    "    for line in f:    #对每条记录\n",
    "        cols = line.strip().decode().split(\",\")\n",
    "        uniqueUsers.add(cols[0])   #第一列为用户ID\n",
    "        uniqueEvents.add(cols[1])   #第二列为活动ID\n",
    "        \n",
    "        #eventsForUser[cols[0]].add(cols[1])    #该用户参加了这个活动\n",
    "        #usersForEvent[cols[1]].add(cols[0])    #该活动被用户参加\n",
    "    f.close()\n",
    "    \n",
    "n_uniqueUsers = len(uniqueUsers)\n",
    "n_uniqueEvents = len(uniqueEvents)\n",
    "\n",
    "print(\"number of uniqueUsers :%d\" % n_uniqueUsers)\n",
    "print(\"number of uniqueEvents :%d\" % n_uniqueEvents)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "f1 = open('Events.csv','w')\n",
    "f2 = open('events.csv','rb')\n",
    "f1.write(f2.readline().decode())\n",
    "for line in f2:\n",
    "    cols = line.strip().decode().split(\",\")    \n",
    "    if (cols[0] in uniqueEvents):\n",
    "        f1.write(line.decode())        \n",
    "f1.close()\n",
    "f2.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv('Events.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>event_id</th>\n",
       "      <th>user_id</th>\n",
       "      <th>start_time</th>\n",
       "      <th>city</th>\n",
       "      <th>state</th>\n",
       "      <th>zip</th>\n",
       "      <th>country</th>\n",
       "      <th>lat</th>\n",
       "      <th>lng</th>\n",
       "      <th>c_1</th>\n",
       "      <th>...</th>\n",
       "      <th>c_92</th>\n",
       "      <th>c_93</th>\n",
       "      <th>c_94</th>\n",
       "      <th>c_95</th>\n",
       "      <th>c_96</th>\n",
       "      <th>c_97</th>\n",
       "      <th>c_98</th>\n",
       "      <th>c_99</th>\n",
       "      <th>c_100</th>\n",
       "      <th>c_other</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>684921758</td>\n",
       "      <td>3647864012</td>\n",
       "      <td>2012-10-31T00:00:00.001Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>244999119</td>\n",
       "      <td>3476440521</td>\n",
       "      <td>2012-11-03T00:00:00.001Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3928440935</td>\n",
       "      <td>517514445</td>\n",
       "      <td>2012-11-05T00:00:00.001Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2582345152</td>\n",
       "      <td>781585781</td>\n",
       "      <td>2012-10-30T00:00:00.001Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1051165850</td>\n",
       "      <td>1016098580</td>\n",
       "      <td>2012-09-27T00:00:00.001Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 110 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     event_id     user_id                start_time city state  zip country  \\\n",
       "0   684921758  3647864012  2012-10-31T00:00:00.001Z  NaN   NaN  NaN     NaN   \n",
       "1   244999119  3476440521  2012-11-03T00:00:00.001Z  NaN   NaN  NaN     NaN   \n",
       "2  3928440935   517514445  2012-11-05T00:00:00.001Z  NaN   NaN  NaN     NaN   \n",
       "3  2582345152   781585781  2012-10-30T00:00:00.001Z  NaN   NaN  NaN     NaN   \n",
       "4  1051165850  1016098580  2012-09-27T00:00:00.001Z  NaN   NaN  NaN     NaN   \n",
       "\n",
       "   lat  lng  c_1   ...     c_92  c_93  c_94  c_95  c_96  c_97  c_98  c_99  \\\n",
       "0  NaN  NaN    2   ...        0     1     0     0     0     0     0     0   \n",
       "1  NaN  NaN    2   ...        0     0     0     0     0     0     0     0   \n",
       "2  NaN  NaN    0   ...        0     0     0     0     0     0     0     0   \n",
       "3  NaN  NaN    1   ...        0     0     0     0     0     0     0     0   \n",
       "4  NaN  NaN    1   ...        0     0     0     0     0     0     0     0   \n",
       "\n",
       "   c_100  c_other  \n",
       "0      0        9  \n",
       "1      0        7  \n",
       "2      0       12  \n",
       "3      0        8  \n",
       "4      0        9  \n",
       "\n",
       "[5 rows x 110 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(13418, 110)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 13418 entries, 0 to 13417\n",
      "Columns: 110 entries, event_id to c_other\n",
      "dtypes: float64(2), int64(103), object(5)\n",
      "memory usage: 11.3+ MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "event_id          0\n",
       "user_id           0\n",
       "start_time        0\n",
       "city           7092\n",
       "state          8868\n",
       "zip           12004\n",
       "country        7065\n",
       "lat            5356\n",
       "lng            5356\n",
       "c_1               0\n",
       "c_2               0\n",
       "c_3               0\n",
       "c_4               0\n",
       "c_5               0\n",
       "c_6               0\n",
       "c_7               0\n",
       "c_8               0\n",
       "c_9               0\n",
       "c_10              0\n",
       "c_11              0\n",
       "c_12              0\n",
       "c_13              0\n",
       "c_14              0\n",
       "c_15              0\n",
       "c_16              0\n",
       "c_17              0\n",
       "c_18              0\n",
       "c_19              0\n",
       "c_20              0\n",
       "c_21              0\n",
       "              ...  \n",
       "c_72              0\n",
       "c_73              0\n",
       "c_74              0\n",
       "c_75              0\n",
       "c_76              0\n",
       "c_77              0\n",
       "c_78              0\n",
       "c_79              0\n",
       "c_80              0\n",
       "c_81              0\n",
       "c_82              0\n",
       "c_83              0\n",
       "c_84              0\n",
       "c_85              0\n",
       "c_86              0\n",
       "c_87              0\n",
       "c_88              0\n",
       "c_89              0\n",
       "c_90              0\n",
       "c_91              0\n",
       "c_92              0\n",
       "c_93              0\n",
       "c_94              0\n",
       "c_95              0\n",
       "c_96              0\n",
       "c_97              0\n",
       "c_98              0\n",
       "c_99              0\n",
       "c_100             0\n",
       "c_other           0\n",
       "Length: 110, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train = train.drop(['event_id','user_id','start_time','city','state','zip','country','lat','lng'],axis=1).values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(13418, 101)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# K-means聚类方法\n",
    "# CH_scores计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "def K_cluster_analysis(K,x_train):\n",
    "    start = time.time()\n",
    "    \n",
    "    print('K-means begin with clusters: {}'.format(K))\n",
    "    \n",
    "    mb_kmeans = MiniBatchKMeans(n_clusters=K)\n",
    "    mb_kmeans.fit(x_train)\n",
    "    \n",
    "    CH_score = metrics.silhouette_score(x_train,mb_kmeans.predict(x_train))\n",
    "    \n",
    "    end = time.time()\n",
    "    print('CH_score: {}, time elaps: {}'.format(CH_score, int(end-start)))\n",
    "    \n",
    "    return CH_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "K-means begin with clusters: 10\n",
      "CH_score: 0.42033438912114013, time elaps: 6\n",
      "K-means begin with clusters: 20\n",
      "CH_score: 0.2790264665028227, time elaps: 5\n",
      "K-means begin with clusters: 30\n",
      "CH_score: 0.19806123030098458, time elaps: 5\n",
      "K-means begin with clusters: 40\n",
      "CH_score: 0.14938530288214036, time elaps: 5\n",
      "K-means begin with clusters: 50\n",
      "CH_score: 0.14098453947062506, time elaps: 5\n",
      "K-means begin with clusters: 60\n",
      "CH_score: 0.13435236214659907, time elaps: 5\n",
      "K-means begin with clusters: 70\n",
      "CH_score: 0.12429744350931075, time elaps: 5\n",
      "K-means begin with clusters: 80\n",
      "CH_score: 0.06337795232977436, time elaps: 5\n",
      "K-means begin with clusters: 90\n",
      "CH_score: 0.08067602463559086, time elaps: 5\n",
      "K-means begin with clusters: 100\n",
      "CH_score: 0.0946205253459958, time elaps: 5\n"
     ]
    }
   ],
   "source": [
    "Ks = [10,20,30,40,50,60,70,80,90,100]\n",
    "CH_scores = []\n",
    "for K in Ks:\n",
    "    ch = K_cluster_analysis(K,x_train)\n",
    "    CH_scores.append(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl8VfWd//HXJ/sKSUgCSFYlLiCypSxiq91xbKGLdkDbqtUyzqidqTOPGTvTxzjD/Drt2I6d6UgXu6i1KFK70UWt49YRAQmbCgiEJRDWkIQ1hGyf3x/3ghcI5AaSnJvc9/PxyCM553zPvZ97Hyfvc+73nPO95u6IiEh8SAi6ABER6TsKfRGROKLQFxGJIwp9EZE4otAXEYkjCn0RkTii0BcRiSMKfRGROKLQFxGJI0lBF3C6/Px8LysrC7oMEZF+ZcWKFfvdvaCrdjEX+mVlZVRVVQVdhohIv2JmNdG0U/eOiEgcUeiLiMQRhb6ISBxR6IuIxBGFvohIHFHoi4jEEYW+iEgcGTChf7CplYde2MimvYeDLkVEJGYNmNDvcOcHr27m0de3BV2KiEjMGjChn5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gdIR//6ava+tr7v4Vdy9y9zJCJ+hecvdbgJcJDcQHcfJeALj7HmCHmV0WnvVBYB1xuG2EbQemmFlG+P/mxPsRl9tHhLNtD4uAz4ev4pkCHDzRDXQhdHPWBTKza4D/A97i3X7sfyTUr78QKCG0sd/kXQw2N5CY2XXA37n7x8IjrC4gdAJvFfBZdz8eZH19xczGAT8CUgiNMHs7oYOtuNw2zOxfCX2VahuhbeFOQv3UcbF9mNlTwHWERtPcCzwA/JpOtofwjvFhQlf7NAG3u3vVBdeg0BcRiR/q3hERiSMKfRGROKLQFxGJIwp9EZE4otAXEYkjCn0RkTii0BcRiSMKfRGROPL/AVweW4IQHb/5AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(Ks,np.array(CH_scores))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分析：在K=10的时候CH_scores最高，因此，可以进一步对其进行优化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "K-means begin with clusters: 2\n",
      "CH_score: 0.6537476570742018, time elaps: 6\n",
      "K-means begin with clusters: 3\n",
      "CH_score: 0.6246150860382779, time elaps: 6\n",
      "K-means begin with clusters: 4\n",
      "CH_score: 0.5772708666623676, time elaps: 6\n",
      "K-means begin with clusters: 5\n",
      "CH_score: 0.46518350315546575, time elaps: 6\n",
      "K-means begin with clusters: 6\n",
      "CH_score: 0.5332862476426331, time elaps: 6\n",
      "K-means begin with clusters: 7\n",
      "CH_score: 0.4389915759692339, time elaps: 5\n",
      "K-means begin with clusters: 8\n",
      "CH_score: 0.4513241069007471, time elaps: 5\n",
      "K-means begin with clusters: 9\n",
      "CH_score: 0.46859941721568743, time elaps: 5\n",
      "K-means begin with clusters: 10\n",
      "CH_score: 0.4445084095733055, time elaps: 6\n"
     ]
    }
   ],
   "source": [
    "Ks1 = [2,3,4,5,6,7,8,9,10]\n",
    "CH_scores_1 = []\n",
    "for K1 in Ks1:\n",
    "    ch = K_cluster_analysis(K1,x_train)\n",
    "    CH_scores_1.append(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl8VPW9//HXJxtZWJKQhIQkJAECWVhDCDuiVGSHC9cWVBTRWm/rVm/bW21Virba3i5Wa3u1Ci5VUYsioIIKuLAJYTUbEAiQhCUJgQAhe76/PzL4ixhlAjM5k5nP8/HII5mTM3PeQfOeyfec+X7FGINSSinP4GV1AKWUUm1HS18ppTyIlr5SSnkQLX2llPIgWvpKKeVBtPSVUsqDaOkrpZQH0dJXSikPoqWvlFIexMfqABcLCwsz8fHxVsdQSql2Zfv27WXGmPBL7edypR8fH09mZqbVMZRSql0RkcP27KfDO0op5UG09JVSyoNo6SullAfR0ldKKQ+ipa+UUh5ES18ppTyIlr5SSnkQtyn9xkbD797P5VBZpdVRlFLKZdlV+iIyUUT2iki+iPzyW/b5vojkiEi2iLzWbHuDiOyyfaxwVPCLHTpZydKtR5j81Oe8ua0QXftXKaW+6ZKlLyLewDPAJCAFmCsiKRftkwg8AIwyxqQC9zX7dpUxZpDtY7rjon9dz/COrL5vLANjgvnFsj3c+a/tlFfWOutwSinVLtnzSj8DyDfGHDTG1AJLgRkX7fND4BljzCkAY0yJY2Pap3twAK/ePowHJyexLq+EiU9+xmf7Sq2IopRSLsme0o8GCpvdLrJta64P0EdENorIFhGZ2Ox7/iKSads+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8x5Y0w98CnwH1aFMcZ8BpRftHkG8JLt65eAmY4+rluUfnMiEg8MBr6wNkkT2xDKLqAE+MgY4xK5gCeBXwCNVge5iAE+FJHtInKH1WFsegKlwBLbcNjzIhJkdagWzAFetzqEMaYY+CNwBDgGVBhjPrQ2FQBZwFgR6SoigcBkINbiTBfrZow5Bk0vZoEIRx/ArUpfRDoCy4D7jDFnrM4DYIxpsP3pHQNk2P7EtJSITAVKjDHbrc7SglHGmDRgEk3DdGOtDkTTq9Y04B/GmMFAJU74s/tKiIgfMB14ywWyhND0ijUB6A4EichN1qYCY0wu8HvgI2A1sJumoWGP4jalLyK+NBX+q8aYt63OczHbcMAnfHMMzwqjgOkicghYClwjIv+yNlITY8xR2+cSmsamM6xNBEARUNTsr7R/0/Qk4EomATuMMSesDgJ8DygwxpQaY+qAt4GRFmcCwBjzgjEmzRgzlqahlf1WZ7rICRGJArB9LnH0Adyi9EVEaBpvzTXG/NnqPBeISLiIBNu+DqDplyHP2lRgjHnAGBNjjImnaUhgnTHG8ldiIhIkIp0ufA1MoOlPcksZY44DhSLS17ZpPJBjYaSWzMUFhnZsjgDDRSTQ9rs5Hhc58S0iEbbPPYBZuM6/2QUrgFtsX98CvOvoA/g4+gEtMgqYB3xpGz8HeNAY876FmQCigJdExJumJ9g3jTEuc3mkC+oGvNPUE/gArxljVlsb6St3A6/ahlEOArdanOcrtvHpa4EfWZ0FwBjzhYj8G9hB0/DJTlznHbDLRKQrUAf8xBhzyqogIvI6MA4IE5Ei4BHgCeBNEbmNpifP6x1+XH1HrlJKeQ63GN5RSillHy19pZTyIFr6SinlQbT0lVLKg2jpK6WUB9HSV0opD6Klr5RSHkRLXymlPMj/A/oAsOtbKta8AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(Ks1,np.array(CH_scores_1))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分析：在K=2的时候CH_scores最高，因此可以把数据分为两类，此时是最优解"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 显示聚类结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHRtJREFUeJzt3X1wXNWZ5/HvIyEbLF6MZRsbjHD8MuMwiQ2JygOVbG2GneI1i6ldoADPwFIQUjuEgskLAzPUbiW1Q4WarfCy2algYxJPhpi3JEAIMWEcIOxWCiPzasf2GhwMwo5lbGzLGIQlP/vHbVmy3ael07qtVp/+faq6uu/R7XvPbbWfvv710bnm7oiISFoaqt0BERHJn4q7iEiCVNxFRBKk4i4ikiAVdxGRBKm4i4gk6IihrGRmbwNdQC/Q4+5tZjYBeAiYDrwNXOruH1SmmyIiEiPmzP0v3P00d28rLN8CrHD32cCKwrKIiIwCw4llFgBLC4+XAhcNvzsiIpIHG8pfqJrZH4APAAfudfdFZrbT3ccPWOcDdz++yHOvA64DaG5u/vycOXNy67yISD1YtWrV++4+KeY5Q8rcgS+4+2Yzmww8Y2brhroDd18ELAJoa2vz9vb2mP6JiNQ9M9sU+5whxTLuvrlw3wn8HJgPbDWzqYUdTwU6Y3cuIiKVMWhxN7NmMzum7zFwNrAaeAK4qrDaVcDjleqkiIjEGUoscwLwczPrW/8n7r7czF4CHjaza4B3gEsq100REYkxaHF3943AvCLt24H/UIlOiYjI8OgvVEVEEqTiLiKSIBV3EZEEqbiLiCRIxV1EJEEq7iIiCVJxFxFJkIq7iEiCVNxFRBKk4i4ikiAVdxGRBKm4i4g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4CZ3352d1KXL3XuB08xsPPBz4NPFVhvZXlWOmX0Z6HT3VWb2pb7mIqsmc8wFX3D3zWY2GXjGzNaVs5HUz9w7gJMHLE8DNlepLyNtq5lNBSjcd1a5P7kysyaywv6Au/+s0Jz0Mfdx953Ac2TfN4w3s76TtNTe318ALjSzt8ki1bPIzuRTPmbcfXPhvpPsQ3w+Zby3Uy/uLwGzC9+ujwEuA56ocp9GyhPAVYXHVwGPV7EvuSrkrkuAte7+vQE/SvmYJxXO2DGzo4C/JPuu4Vng4sJqSR2zu9/q7tPcfTrZv93fuPtCEj5mM2s2s2P6HgNnA6sp472d/F+omtn5ZJ/2jcD97v6PVe5S7sxsGfAlsqlQtwL/HXgMeBhoBd4BLnH3Q790rUlm9kXgBeAN+rPYvyfL3VM95rlkX6Q1kp2UPezu3zGzGWRntROAV4C/cvfu6vW0MgqxzDfd/cspH3Ph2H5eWDwC+Im7/6OZtRD53k6+uIuI1KPUYxkRkbqk4i4ikiAVdxGRBKm4i4gkSMVdRCRBKu4iIglScRcRSdD/B0+m6MJVk2syAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#显示聚类结果\n",
    "#画出聚类结果，每一类用一种颜色\n",
    "colors = ['b','r']\n",
    "\n",
    "n_clusters = 2\n",
    "mb_kmeans = MiniBatchKMeans(n_clusters = n_clusters)\n",
    "mb_kmeans.fit(x_train)\n",
    "\n",
    "y_train_pred = mb_kmeans.labels_\n",
    "cents = mb_kmeans.cluster_centers_#质心\n",
    "\n",
    "for i in range(n_clusters):\n",
    "    index = np.nonzero(y_train_pred==i)[0]\n",
    "    x1 = x_train[index,0]\n",
    "    x2 = x_train[index,1]\n",
    "    for j in range(len(x1)):\n",
    "        if j < 500:  #每类打印500个\n",
    "            plt.text(x1[j],x2[j],'o',color=colors[i],fontdict={'weight': 'bold', 'size': 9})\n",
    "\n",
    "plt.axis([-5,50,-5,50])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分析：通过可视化图片可以看出，两类的边界处有些许数据交织在一起，1类主要集中在0-10之间，2类的较为散，还有一些噪声点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
